< previous page page_84 next page >

Page 84
others may be slower than normal, and still others may not work at all. To avoid problems, you should always shut your computer down and restart it after changing the color depth.
The sections that follow explain some methods you can use to manipulate images using different color models.
Bitmaps
Visual Basic's Point function lets you determine the color of any pixel on a form or picture box. Conversely, the PSet command lets you set the color of any pixel. These commands are easy to use, but they are quite slow. A complex imaging program might need to examine and modify every pixel in a picture. Using these commands is tedious for all but the smallest pictures.
You can greatly improve the performance of your program by using API functions to process images. While the bitmap API functions are faster than Visual Basic's method, they are also much more complicated.
The following sections briefly describe ways you can use API functions make image manipulation faster. Later chapters use these functions more extensively.
Device-Dependent Bitmaps
A device-dependent bitmap is an image that is ready for display at a particular color resolution. You could display a device-dependent bitmap directly on a form or picture box.
The Windows API includes several functions for manipulating device-dependent bitmaps. The GetObject API function describes an object currently selected by a drawing object. For example, you can use GetObject to retrieve information about the bitmap, pen, brush, font, or logical color palette used by a picture box.
The following code shows the Visual Basic declaration for the GetObject API function. Visual Basic has its own GetObject function, so the declaration gives this function the name GetObjectAPI to avoid ambiguity. In the gdi32 library, the function is known as GetObjectA. The Visual Basic program refers to the function as GetObjectAPI.
e10a6a0a59f035e870d90cca05b85fce.gif
Private Declare Function GetObjectAPI Lib "gdi32" _
    Alias "GetObjectA" (ByVal hObject As Long, _
    ByVal nCount As Long, lpObject As Any) As Long
The function's hObject parameter should be the handle of a bitmap, pen, brush, font, or logical palette. If you set a form or picture box's AutoRedraw property to true, Visual Basic stores a handle to the object's persistent bitmap in its Image property, and you can use that to retrieve bitmap information.
The lpObject parameter is a pointer to the data structure that will hold the information about the object. The nCount parameter gives the size of the lpObject data structure. For example, the following code gets information about the picCanvas control's bitmap.

 
< previous page page_84 next page >